// pages/classroom/classroom.js
import request from "../../utils/request";
Page({


  /**
   * 页面的初始数据
   */
  data: {
    // addressList:["教室地址","雅安校区","都江堰校区","温江校区"],
    classroomList:'',
    treeData: {
      text: '教室地址',
      id: 0,
      childMenus: [
        {
          text: '雅安校区',
          id: 1,
          childMenus: [
            {
              text: '一教',
              id: 11,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A201-A219',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 11,
                    },
                    {
                      text: 'B201-B219',
                      id: 12,
                    },
                  ]
                },
              ]
            },
            {
              text: '二教',
              id: 12,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A101-A119',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 1111,
                    },
                    {
                      text: 'B201-B219',
                      id: 2222,
                    },
                  ]
                },
              ]
            },
          ]
        },
        {
          text: '温江校区',
          id: 1,
          childMenus: [
            {
              text: '一教',
              id: 2,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A101-A119',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 1111,
                    },
                    {
                      text: 'B201-B219',
                      id: 2222,
                    },
                  ]
                },
              ]
            },
            {
              text: '二教',
              id: 2,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A101-A119',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 1111,
                    },
                    {
                      text: 'B201-B219',
                      id: 2222,
                    },
                  ]
                },
              ]
            },
          ]
        },
        {
          text: '都江堰校区',
          id: 1,
          childMenus: [
            {
              text: '一教',
              id: 2,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A101-A119',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 1111,
                    },
                    {
                      text: 'B201-B219',
                      id: 2222,
                    },
                  ]
                },
              ]
            },
            {
              text: '二教',
              id: 2,
              childMenus: [
                {
                  text: 'A区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'A101-A119',
                      id: 1111,
                    },
                    {
                      text: 'A101-A119',
                      id: 2222,
                    },
                  ]
                },
                {
                  text: 'B区',
                  id: 3,
                  childMenus: [
                    {
                      text: 'B101-B119',
                      id: 1111,
                    },
                    {
                      text: 'B201-B219',
                      id: 2222,
                    },
                  ]
                },
              ]
            },
          ]
        },
      ]
    },
    address_temp:'雅安校区'
  },
    //事件处理函数
    tapItem: function (e) {
        if(e.detail.itemid==0){
          this.setData({
            address_temp : "雅安校区"
          })
        }else if(e.detail.itemid==1111){
          if(this.data.address_temp.indexOf("楼")!=-1){
            this.setData({
              address_temp:this.data.address_temp.replace("2楼","1楼")
            })
        }else{
          this.setData({
            address_temp : this.data.address_temp+"1楼"
          })
        }
        }else if(e.detail.itemid==2222){
          if(this.data.address_temp.indexOf("楼")!=-1){
              this.setData({
                address_temp:this.data.address_temp.replace("1楼","2楼")
              })
          }else{
            this.setData({
              address_temp : this.data.address_temp+"2楼"
            })
          }
        }else if(e.detail.itemid==1){
            this.setData({
              address_temp: e.detail.address
            });
        }else {
          this.setData({
            address_temp : this.data.address_temp+e.detail.address
          })
        }
    
    if(this.data.address_temp!==''){
      console.log(this.data.address_temp)
      var address = this.data.address_temp;
        this.getClassroomList(address);
     }
    },
    async  getClassroomList(key){
      let result = await request('classroom_ms1.0/classroom/search',{key},'GET');
      var data = result.data;
      this.setData({
          classroomList:data
      })
    },

  jumpDetails:function(e){
    var classroomId = e.currentTarget.id;
    wx.navigateTo({
      url: 'classroom_details/classroom_details?classroomId='+classroomId,
    })
    },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.getClassroomList(this.data.address_temp);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})